package com.weyoung.admin.controller;


import cn.dev33.satoken.stp.StpUtil;
import com.weyoung.admin.dto.req.UserLoginReqDTO;
import com.weyoung.admin.dto.req.UserRegisterReqDTO;
import com.weyoung.admin.mapper.UserMapper;
import com.weyoung.admin.service.UserService;
import com.weyoung.common.consatant.result.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Web端 - 用户接口管理
 */
@RestController
@RequestMapping("admin/user")
@Tag(name = "Web端-用户接口")
@Slf4j
@RequiredArgsConstructor
public class UserController {

    private final UserService userService;


    /**
     * 登录
     *
     * @param requestParam 用户名+密码
     * @return 成功
     */
    @PostMapping("/login")
    @Operation(summary = "用户登录")
    public Result<Void> login(@RequestBody UserLoginReqDTO requestParam) {
        return Result.success(userService.login(requestParam));
    }

    /**
     * 注册
     *
     * @param requestParam 测试为用户名+密码，后面还加上 手机号+验证码
     * @return Void
     */
    @PostMapping("/register")
    @Operation(summary = "用户注册")
    public Result<Void> register(@RequestBody UserRegisterReqDTO requestParam){
        return Result.success(userService.register(requestParam));
    }

    /**
     * 退出登录
     *
     * @return void
     */
    @PostMapping("logout")
    @Operation(summary = "退出登录")
    public Result<Void> logout() {
        StpUtil.logout();
        return Result.success();
    }


}    